/** 
 *  @file
 *  @brief   8节点6面体实体单元,上表面四点不共面
 *  @author  lijiayang
 *  @date    2024.05.10
 *  @version  v1.0
 *  @par Copyright(c):  ShenGong  Simulation corporation
 */

#pragma once
#include "DataStructure/Input/Element/CHEXAData.h"
#include "DataStructure/Input/Solver/DOFDirections.h"
#include "DBManager/Database/DatabaseFactory.h"
#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Element/IElementService.h"
#include "DBManager/IService/Input/Property/IPSOLIDService.h"

using SG::DataStructure::FEM::DOFDirections;
using namespace SG::DBManager;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;

/// 8节点6面体实体单元
class Cube_OneHexa8EleWarpFace
{
public:
    Cube_OneHexa8EleWarpFace()
    {
        DB_SERVICEFACTORY -> ClearDatabase();
        Input (DB_SERVICEFACTORY);
    }

    /// @brief 写入模型数据
    void        Input (const DBServiceFactorySP dbServiceFactory);
    DBServiceFactorySP GetModel () {return DB_SERVICEFACTORY;}
};

void Cube_OneHexa8EleWarpFace::Input (const DBServiceFactorySP dbServiceFactory)
{
    // 节点写入
    const auto& nodeRepository = dbServiceFactory ->get<INodeService>();
    SG::DataStructure::FEM::NodeData node;
    node.m_id = 1;
    nodeRepository ->Add  (node);
    node.m_id = 2;
    nodeRepository ->Add  (node);
    node.m_id = 3;
    nodeRepository ->Add  (node);
    node.m_id = 4;
    nodeRepository ->Add  (node);
    node.m_id = 5;
    node.m_x[0] = 5.0;
    node.m_x[1] = 5.0;
    node.m_x[2] = 9.0;
    nodeRepository ->Add  (node);
    node.m_id = 6;
    node.m_x[0] = 0.0;
    node.m_x[1] = 5.0;
    // 修改节点坐标，形成warp 面
    // node.m_x[2] = 5.0;
    node.m_x[2] = 6.0;
    nodeRepository ->Add  (node);
    node.m_id = 7;
    node.m_x[0] = 0.0;
    node.m_x[1] = 0.0;
    node.m_x[2] = 5.0;
    nodeRepository ->Add  (node);
    node.m_id = 8;
    node.m_x[0] = 5.0;
    node.m_x[1] = 0.0;
    node.m_x[2] = 6.0;
    nodeRepository ->Add  (node);

    // 截面属性写入
    {
        SG::DataStructure::FEM::PSOLIDData ElementProperty;
        ElementProperty.m_id = 1;
        ElementProperty.m_mId = 1;
        ElementProperty.m_mCId = 1;
        dbServiceFactory -> get<IPSOLIDService>()->Add (ElementProperty);
        ElementProperty.m_id = 2;
        ElementProperty.m_mId = 3;
        ElementProperty.m_mCId = 2;
        dbServiceFactory -> get<IPSOLIDService>()->Add (ElementProperty);
    }
    // 写入单元i
    {
        SG::DataStructure::FEM::CHEXA8Data ElementData;
        ElementData.m_id = 1;
        ElementData.m_pId = 1;
        ElementData.Set8Points ( {1,2,3,4,5,6,7,8});
        dbServiceFactory -> get<IElementService>()->Add (ElementData);
    }
    // 节点固定约束

    // 工况
    {
        // subcase.
        SG::DataStructure::FEM::Subcase subcase;
        // subcase.m_id   = 1;
        // subcase.m_spc  = 1;
        // subcase.m_load = 1;
        // dbServiceFactory->get<ISubcaseService> ()->Add (subcase);
        subcase.AddParameter({"SUBCASE","1"});
        subcase.AddParameter({"SOL","101"});
        subcase.AddParameter({"SPC","1"});
        subcase.AddParameter({"LOAD","1"});
        dbServiceFactory->get<ISubcaseService> ()->Initial (subcase.Dump());
    }
}